<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        .active {
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="box">
        <ul>
            <li v-for="item,index in datalist" :class="current===index?'active':''" @click="handleClick(index)">{{item}}</li>
        </ul>
    </div>
    <script>
        var obj = {
            data() {
                return {
                    datalist: ["11", "22", "33"],
                    current: 0 //当前点击的索引值
                }
            },
            methods: {
                handleClick(index) {
                    this.current = index
                }
            }
        }

        var app = Vue
            .createApp(obj)
            .mount('#box')
    </script>
</body>

</html>